package com.xu.mapper;

import com.xu.pojo.Cart;
import com.xu.pojo.Product;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CartMapper {

    @Insert("insert into bread.cart (uid,pid) values (#{uid},#{pid})")
    int addCart(Cart cart);

    @Select("select * from bread.cart")
    List<Cart> queryAllCart();

    @Select("select p.pname,p.pprice,p.url from bread.cart join product p ON cart.pid = p.id where uid=#{uid}")
    List<Cart> queryCartByUid(int uid);

    @Select("select count(*) from bread.cart where pid=#{pid} and uid=#{uid}")
    int getNumByUidAndPid(@Param("pid") int pid, @Param("uid") int uid);

    @Select("select count(*) from bread.cart where uid=#{uid}")
    int getNumByUid( @Param("uid") int uid);

}
